"""Monitor a bsudaq data stream from a serial port"""

import time
import serial
import traceback


def openser():
    ser = serial.Serial()
    ser.port = "com26"
    ser.baudrate = 9600
    ser.timeout = 1.0
    ser.open()
    return ser


def nextword(ser):
    c = ser.readline()
    return c.strip()


def processser(ser):
    nextword(ser)
    while 1:
        z = int(nextword(ser))
        nsy = int(round(z/1000.0))
        print "%5d %s" % (z, nsy * '-')


def main():
    try:
        ser = openser()
        processser(ser)
    except KeyboardInterrupt, k:
        print "  *** keyboard interrupt ***"
    except Exception, e:
        traceback.print_exc()
    finally:
        try:
            ser.close()
        except Exception, e:
            print(e)


if __name__ == "__main__":

    main()

